package net.sparrow.event;

import java.lang.reflect.Field;

import net.sparrow.module.Module;
import net.sparrow.util.Util;

public class SpDataEntry {

	
	public Field moduleField;
	public Module module;
	
	
	public SpDataEntry(Module m, Field o) {
		moduleField = o;
		module = m;
	}
	
	public void setData(Object data) throws IllegalArgumentException, IllegalAccessException {
			Class fieldClazz = moduleField.getType();
			if(fieldClazz.isAssignableFrom(Double.class) && (data instanceof Integer)) {
				data = ((Integer)data).doubleValue();
			} //if we gave an int but it wanted a double, that's ok: 3 is the same as 3.0
			moduleField.set(module, data);
			Util.debug("Set " + moduleField.getName() + " to " + data.toString());
	}
	
	public Object getData() {
		try {
			return moduleField.get(module);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
